from aiogram import types
from aiogram_dialog import DialogManager
from fluentogram import TranslatorRunner

from poker_bot.core.models.enums.account import AccountStatus
from poker_bot.database.services import AccountService, UserService


async def select_account(
    call: types.CallbackQuery, __, manager: DialogManager, account_id: str, **kwargs
):
    locale: TranslatorRunner = manager.middleware_data.get("locale")
    account_service: AccountService = manager.middleware_data.get("account_service")
    user_service: UserService = manager.middleware_data.get("user_service")
    account_id = int(account_id)

    account = await account_service.get_account_by_id(account_id)
    if not account.status == AccountStatus.approved:
        await call.answer(locale.get("wait-for-account-moderation-msg"))
        return
    await user_service.change_selected_account(call.from_user.id, account_id)

    await call.answer(locale.get("account-changed"))

    await manager.done()
